package com.acidu.blogtag.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.acidu.blogtag.domain.AciduBlogTag;
import com.acidu.blogtag.service.IAciduBlogTagService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 博文标签关系Controller
 * 
 * @author ruoyi
 * @date 2025-01-22
 */
@RestController
@RequestMapping("/acidu-blogs/tag")
public class AciduBlogTagController extends BaseController
{
    @Autowired
    private IAciduBlogTagService aciduBlogTagService;

    /**
     * 查询博文标签关系列表
     */
    @PreAuthorize("@ss.hasPermi('acidu-blogs:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(AciduBlogTag aciduBlogTag)
    {
        startPage();
        List<AciduBlogTag> list = aciduBlogTagService.selectAciduBlogTagList(aciduBlogTag);
        return getDataTable(list);
    }

    /**
     * 导出博文标签关系列表
     */
    @PreAuthorize("@ss.hasPermi('acidu-blogs:tag:export')")
    @Log(title = "博文标签关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AciduBlogTag aciduBlogTag)
    {
        List<AciduBlogTag> list = aciduBlogTagService.selectAciduBlogTagList(aciduBlogTag);
        ExcelUtil<AciduBlogTag> util = new ExcelUtil<AciduBlogTag>(AciduBlogTag.class);
        util.exportExcel(response, list, "博文标签关系数据");
    }

    /**
     * 获取博文标签关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('acidu-blogs:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aciduBlogTagService.selectAciduBlogTagById(id));
    }

    /**
     * 新增博文标签关系
     */
    @PreAuthorize("@ss.hasPermi('acidu-blogs:tag:add')")
    @Log(title = "博文标签关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AciduBlogTag aciduBlogTag)
    {
        return toAjax(aciduBlogTagService.insertAciduBlogTag(aciduBlogTag));
    }

    /**
     * 修改博文标签关系
     */
    @PreAuthorize("@ss.hasPermi('acidu-blogs:tag:edit')")
    @Log(title = "博文标签关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AciduBlogTag aciduBlogTag)
    {
        return toAjax(aciduBlogTagService.updateAciduBlogTag(aciduBlogTag));
    }

    /**
     * 删除博文标签关系
     */
    @PreAuthorize("@ss.hasPermi('acidu-blogs:tag:remove')")
    @Log(title = "博文标签关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aciduBlogTagService.deleteAciduBlogTagByIds(ids));
    }
}
